package com.example.recruitment_website.service.Impl;

import com.example.recruitment_website.domain.User;
import com.example.recruitment_website.repository.UserRepository;
import com.example.recruitment_website.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserImpl implements UserService {
    @Autowired
    UserRepository userRepository;

    @Override
    public int login(String name, String imgUrl, String openId) {

        User u = userRepository.findByOpen_id(openId);

        if(u == null){
            User user = new User(name, imgUrl, openId);
            try {
                userRepository.save(user);
            }catch (Exception e){
                return 0;
            }
            return userRepository.findByOpen_id(openId).getId();
        }else {
            return u.getId();
        }


    }
}
